Skip to content

elasticsearch - #151

Merged
stereosteve merged 34 commits into
mainfrom
sp-es
Jun 25, 2025
Merged

stereosteve merged 34 commits into
mainfrom
sp-es

Conversation

@stereosteve

@stereosteve stereosteve commented Jun 21, 2025 •

Copy link
Copy Markdown
Contributor
  • Adds an esindexer package.

    • This can build indexes from scratch: users, tracks, playlists, socials.
    • It can also "listen" to postgres NOTIFY events and re-index documents, similar to es-indexer.
    • It doesn't have an analogous "catchup" mode based on blocknumber. Rebuilding the non-socials indexes only takes a few minutes per index, so we might not need the "catchup" mode.
  • Adds api/searchv1 subpackage with some structs to build elastic DSL.

    • The file api/v1_search.go has functions for searchTracks etc that populate the structs from searchv1 subpackage to build the DSL and do search etc. Probably the bridge team would vote to inlining the contents of searchv1 into the endpoint files since we like to colocate the query logic with the endpoint. In this case it would probably make sense to move some stuff out of v1_search.go into subfiles like v1_search_users.go which would have the DSL builder and the search helper function etc.

Currently the indexer can run on the same box as our Elasticsearch. The Makefile has been updated to deploy the indexer in "listen" mode: make esindexer-staging or make esindexer-production. We don't need no stinkin Pulumi in these parts.

More Notes

  • /search/autocomplete, /search/full, /search/tags all use the same handler function. Conditional logic will only personalize results in the full endpoint, and the tags will modify the initial must portion of the DSL to use the tags field.
  • I declined to port over the complicated painless script scoring... and stuck with more trad function score and should boosting stuff. The fact that it didn't factor in _score basically invalidates the notion that should clauses can help re-rank results. The result sorting will be different but in eyeballing 30 odd queries I thought the bridge results were better... more likely to honor exact title matches and less likely to randomly show some rando track with low numbers... 🤷 .
  • I pulled out JsonAssert because I was initially using it in esindexer package... but I'm not even anymore... so I guess I could just move it back into api package.
  • Logging should be standardized.

Query still needs some work to match current results.
so indexer can mimic es-indexer typescript behavior.
Rather than do some subclass style nonsense, just have a single indexer instance,
and index configs are just data structs that the single indexer can use.

This will make it easier for that indexer to have a listener and respond appropriately.
Also uses painless to "patch" social documents.
@stereosteve
stereosteve marked this pull request as ready for review June 24, 2025 14:49

@raymondjacobson raymondjacobson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send it

Comment thread api/auth_middleware.go Resolved
Comment thread api/searchv1/dsl_helpers.go Resolved
Comment thread api/searchv1/dsl_helpers.go Resolved
Comment thread api/searchv1/dsl_helpers.go Resolved
"field_value_factor": {
"field": %q,
"factor": 100,
"modifier": "ln2p",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the ln2p?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because the python codebase used it. It adds 2 to the value to smooths out the lower end of the range a bit...

Comment thread api/v1_search_test.go Resolved
Comment thread esindexer/indexer.go Resolved
Comment thread esindexer/indexer.go
painlessRemoveEntity := `
def user = ctx._source;
def idx = user[params.fieldName].indexOf(params.entityId);
if (idx > -1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be > 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because indexOf returns -1 if not found... but 0 is a valid found index.

return nil
}))

// this fires all the time...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, we never use plays in current search? that might be a nice signal to add... some day

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did index it in discovery provider and used it as a ranking signal. But in the go version we're not currently indexing it... and just using repost count as ranking signal.

Comment thread static/searchtest.html Resolved
@stereosteve
stereosteve merged commit c5f7b84 into main Jun 25, 2025
@stereosteve
stereosteve deleted the sp-es branch June 25, 2025 17:05
dylanjeffers added a commit that referenced this pull request Nov 12, 2026
## Summary
Audit of feature flags and env toggles in the API. Only one met the bar
for removal.

**Removed**
- `skipAuthCheck` env var (`api/server.go`). When set to true, it turned
off `isAuthorizedRequest` entirely, and production code read it from the
environment. Nothing in this repo, compose, or k8s sets it. Every test
that needs it sets `app.skipAuthCheck = true` on the struct, which still
works. Added in #151 (2025-06) and never used through the env since.
This cuts a dead toggle and an auth bypass at the same time.

**Audited and kept (needs a decision from someone with prod access)**
- `commsMessagePush`: defaults on since #349 (2025-09). The env override
only turns it off. `server_test.go` depends on it to keep the websocket
manager and pg-notify listeners out of the shared test app, so it works
as a test seam. I couldn't confirm prod doesn't set
`commsMessagePush=false`; if it doesn't, the env parse can go, but the
struct field should stay for tests.
- `coreBlockStreamEnabled`: defaults off and arrived in #941 (2026-06,
~5 months ago). I couldn't see the prod env (no RBAC on
deployments/configmaps). If prod has it on, inline it; if it was never
turned on, consider deleting the gRPC stream path.
- `newChainQueueEnabled` / `newChainFlushEnabled` /
`newChainInsecureSkipVerify` / `etlStartingBlockHeight` /
`etlEndingBlockHeight` / `PlayRoutingHosts`: the genesis migration is
still in progress (see `cmd/genesis-writer/ROLLOUT.md`). Not stale yet;
remove them at cutover.

## Test plan
- [x] `go build ./...` and `go vet ./api/`
- [ ] `go test ./api/...` (couldn't run locally because Docker/test DB
was down; CI covers it)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants